//
//  MyBranchMenuWithFourItemView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/16.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "MyBranchMenuWithFourItemView.h"

#import "MyBranchMenuModel.h"
@implementation MyBranchMenuWithFourItemView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor themeColor];
        
    }
    return self;
}

- (void)setData:(NSArray *)data{
    _data = data;
    
    self.cwidth = [UIScreen zj_screenWith] / 4;
    self.cheight = 72 * [UIScreen zj_screenHScale];
    
    for (int i = 0; i < data.count; i ++) {
        MyBranchMenuModel *model = data[i];
        
        HomeImageAndLabelView *cenet = [HomeImageAndLabelView new];
        cenet.homeLabel.textColor = [UIColor whiteColor];
        if (self.textColor) {
            cenet.homeLabel.textColor = self.textColor;
        }
        if (self.messageBgColor) {
            cenet.messageNumber.backgroundColor = self.messageBgColor;
        }
        if (self.messageTextColor) {
            cenet.messageNumber.textColor = self.messageTextColor;
        }
        cenet.homeLabel.text = model.title;
        cenet.homeImageView.image = [UIImage  imageNamed:model.imageString];
        cenet.homeImageView.contentMode = UIViewContentModeCenter;
        cenet.userInteractionEnabled = YES;
        cenet.isTop = YES;
        cenet.tag = 300 + i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCenter:)];
        [cenet addGestureRecognizer:tap];
        
        cenet.frame = CGRectMake(self.cwidth * (i % 4), i / 4  * 80 * [UIScreen zj_screenHScale], self.cwidth, self.cheight);
        [self addSubview:cenet];
        
    }
    
}

/**  小红点显示  */
- (void)setRedViewHideOrShow:(BOOL)isHide{
    HomeImageAndLabelView * cenet = [self viewWithTag:303];
    if (isHide == YES) {
        cenet.redView.hidden = YES;
    }else{
        cenet.redView.hidden = NO;
    }
}

/**  消息数量  */
-(void)setMessageNumberWithNumber:(NSInteger)number{
    HomeImageAndLabelView * cenet = [self viewWithTag:301];
    if (number == 0) {
        cenet.messageNumber.text = @"";
        cenet.messageNumber.hidden = YES;
    }
    else{
        cenet.messageNumber.text = [NSString stringWithFormat:@"%ld" , (long)number];
        cenet.messageNumber.hidden = NO;
    }
}
/**  在线学习数量  */
-(void)setStudyNumberWithNumber:(NSInteger)number{
    HomeImageAndLabelView * cenet = [self viewWithTag:304];
    if (number == 0) {
        cenet.messageNumber.text = @"";
        cenet.messageNumber.hidden = YES;
    }
    else{
        cenet.messageNumber.text = [NSString stringWithFormat:@"%ld" , (long)number];
        cenet.messageNumber.hidden = NO;
    }
}
/**  党建动态  */
-(void)setDynamicNumberWithNumber:(NSInteger)number{
    HomeImageAndLabelView * cenet = [self viewWithTag:300];
    if (number == 0) {
        cenet.messageNumber.text = @"";
        cenet.messageNumber.hidden = YES;
    }
    else{
        cenet.messageNumber.text = [NSString stringWithFormat:@"%ld" , (long)number];
        cenet.messageNumber.hidden = NO;
    }
}

- (void)tapCenter:(UITapGestureRecognizer *)tap{
    if (self.delegate) {
        [self.delegate view:self MyBranchMenuWithFourItem_tapIndex:(tap.view.tag - 300)];
    }
}
@end
